﻿using System;
using System.Collections.Generic;
using Birkelund.QueryStrings.Tokens;
using NUnit.Framework;

namespace Birkelund.QueryStrings.Test
{
    public class StringsTokenTest
    {
        [Test]
        public void RenderTokenValue_ReadValue_RemoveEmptyValues_True()
        {
            Uri initialUrl = new Uri("http://www.test.dk/default.aspx?a=hello;hi;is it you?;");

            StringsToken token = new StringsToken("a", ';');
            token.RemoveEmptyValues = true;
            ICollection<string> values = token.ReadValue(initialUrl);

            Assert.IsTrue(values.Contains("hello"));
            Assert.IsTrue(values.Contains("hi"));
            Assert.IsTrue(values.Contains("is it you?"));
            Assert.IsFalse(values.Contains(string.Empty));
            Assert.AreEqual(3, values.Count);
        }

        [Test]
        public void RenderTokenValue_ReadValue_RemoveEmptyValues_False()
        {
            Uri initialUrl = new Uri("http://www.test.dk/default.aspx?a=hello;hi;is it you?;");

            StringsToken token = new StringsToken("a", ';');
            token.RemoveEmptyValues = false;
            ICollection<string> values = token.ReadValue(initialUrl);

            Assert.IsTrue(values.Contains("hello"));
            Assert.IsTrue(values.Contains("hi"));
            Assert.IsTrue(values.Contains("is it you?"));
            Assert.IsTrue(values.Contains(string.Empty));
            Assert.AreEqual(4, values.Count);
        }

        [Test]
        [ExpectedException(typeof(ArgumentException))]
        public void SeperatorValidation_Negative(
            [Values('?', '&')]
            char candidate
            )
        {
            StringsToken token = new StringsToken("a", candidate);
        }
    }
}
